package com.gz;
import java.util.ArrayList;
import javax.swing.*;
import java.lang.Math;
import java.util.Scanner;

public class test2 {

    public static void main(String[] args) {
        Thread1 thread1 = new Thread1();
        Thread2 thread2 = new Thread2(thread1);
//        thread1.setDaemon(true);
        thread1.start();
        thread2.start();

    }
}

class Thread1 extends Thread {
    private boolean loop=true;
    public void run() {
        while(loop){
            int a=(int)(Math.random()*100+1);
            System.out.println(a);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public void setLoop(boolean loop) {
        this.loop = loop;
    }
}
class Thread2 extends Thread {
    private Thread1 thread1;
    public Thread2(Thread1 thread1) {
        this.thread1 = thread1;
    }

    public void run() {
        Scanner scanner = new Scanner( System.in );
        char b=' ';
        while(true){
            b=scanner.next().toUpperCase().charAt(0);
            if(b=='Q'){
                thread1.setLoop(false);
                break;
            }
        }
    }
}
